﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace TheCup
{
    public class ComparePlayers : IEqualityComparer<Player>
    {
        // de kan overrides i deres respektive klasser, så == fx. er lig nedenstående
        public bool Equals(Player x, Player y)
        {
            return x.Id == y.Id;
        }

        public int GetHashCode(Player codeh)
        {
            return codeh.Id.GetHashCode();
        }
    }

    public enum Sex {
        Herre,
        Dame
    }

    [Table("player")]
    [JsonObject(IsReference = true)]
    public class Player
    {
        [Key]
        [Column("no")]
        public int Id { get; set; }

        public string Initials { get; set; }
        
        [Display(Name="Fornavn")]
        public string GivenName { get; set; }

        [Display(Name = "Efternavn")]
        public string LastName { get; set; }

        [Display(Name = "Køn")]
        public Sex Sex { get; set; }
        
        [DataType(DataType.Date)]
        [Display(Name = "Fødselsdato")]
        //[DisplayFormat(DataFormatString="{0:d}", ApplyFormatInEditMode=true)]
        public DateTime Birthdate { get; set; }

        [DataType(DataType.Password)]
        public string Password { get; set; }
                
        [Display(Name = "Adresse")]
        public string Address { get; set; }

        [Display(Name = "Postnummer")]
        public string ZipCode { get; set; }

        [Display(Name = "By")]
        public string City { get; set; }

        [NotMapped]
        [Display(Name = "Alder")]
        public string Age
        {
            get
            {
                var today = DateTime.Today;
                int age = today.Year - Birthdate.Year;
                if (today.Month < Birthdate.Month || (today.Month == Birthdate.Month && today.Day < Birthdate.Day)) age--;
                return age.ToString();
            }
        }

        [Column("isapproved")]
        [Display(Name = "Aktiv")]
        public bool IsActive { get; set; }

        [Column("dguno")]
        [Display(Name = "Dgu#")]
        public string MemberNumber { get; set; }

        public Nullable<int> CourseId { get; set; }

        [ForeignKey("CourseId")]
        [Display(Name = "Hjemmebane")]
        public virtual Course Course { get; set; }

        public double Hcp { get; set; }

        [Column("Mail")]
        [Display(Name = "Email")]
        public string Email { get; set; }

        [Column("mailupdates")]
        public Nullable<bool> SendEventMails { get; set; }

        [Display(Name = "Mobil")]
        public string MobilePhone { get; set; }


        [NotMapped]
        public string DisplayName
        {
            get
            {
                return string.Concat(this.GivenName, " ", this.LastName);
            }
        }

        [Obsolete]
        [Column("playerid")]
        public Guid uuid { get; set; }

        #region Gear

        public string Driver { get; set; }
        [Display(Name="Jern")]
        public string Irons { get; set; }
        public string Putter { get; set; }
        [Display(Name = "Bolde")]
        public string Balls { get; set; }

        #endregion

        #region Ambitions

        [Display(Name = "Rollemodel")]
        public string RoleModel { get; set; }

        [Display(Name = "Bedste runde")]
        [DataType(DataType.MultilineText)]
        public string BestRound { get; set; }
               
        [Display(Name = "Sæsonmål")]
        [DataType(DataType.MultilineText)]
        public string SeasonObjective { get; set; }
        
        [Display(Name = "Styrker")]
        [DataType(DataType.MultilineText)]
        public string StrongFeatures { get; set; }
        
        [Display(Name = "Svagheder")]
        [DataType(DataType.MultilineText)]
        public string WeakFeatures { get; set; }
        
        #endregion

    }
}